package cn.glccc.common.vo;

import cn.glccc.common.constant.ResultConstant;
import lombok.Data;

import java.io.Serializable;

/**
 * 接口通用返回类
 *
 * @author glccc
 * @date 2024-06-07
 */
@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    public Result() {

    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(ResultConstant.CODE_SUCCESS, ResultConstant.MSG_SUCCESS, null);
    }

    public static <T> Result<T> success(String msg) {
        return new Result<>(ResultConstant.CODE_SUCCESS, msg, null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResultConstant.CODE_SUCCESS, ResultConstant.MSG_SUCCESS, data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result<>(ResultConstant.CODE_SUCCESS, msg, data);
    }

    public static <T> Result<T> failure() {
        return new Result<>(ResultConstant.CODE_FAILURE, ResultConstant.MSG_FAILURE, null);
    }

    public static <T> Result<T> failure(String msg) {
        return new Result<>(ResultConstant.CODE_FAILURE, msg, null);
    }

    public static <T> Result<T> failure(T data) {
        return new Result<>(ResultConstant.CODE_FAILURE, ResultConstant.MSG_FAILURE, data);
    }

    public static <T> Result<T> failure(String msg, T data) {
        return new Result<>(ResultConstant.CODE_FAILURE, msg, data);
    }

    public static <T> Result<T> failure(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

}
